package com.cskaoyan.mall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.product.dto.SaleAttrInfoDTO;
import com.cskaoyan.mall.product.dto.SpuInfoPageDTO;
import com.cskaoyan.mall.product.model.SpuInfo;
import com.cskaoyan.mall.product.query.SpuInfoParam;
import com.cskaoyan.mall.product.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Macro_Ray
 * @since 2024/6/10 下午4:21
 */
@RestController
@RequestMapping("/admin/product/")
public class SpuController {

    @Autowired
    SpuService spuService;

    /**
     * 查询三级分类下的所有SPU信息列表
     */
    // http://124.220.39.95/admin/product/1/10?category3Id=61
    @GetMapping("{page}/{limit}")
    public Result<SpuInfoPageDTO> getSpuInfoListByCate3Id(@PathVariable("page") Integer page,
                                                          @PathVariable("limit") Integer limit,
                                                          @RequestParam("category3Id") Long category3Id) {
        Page<SpuInfo> pageParam = new Page<>(page, limit);
        SpuInfoPageDTO spuInfoPageDTO = spuService.getSpuInfoListByCate3Id(pageParam, category3Id);
        return Result.ok(spuInfoPageDTO);
    }

    /**
     * 查询SPU销售属性列表
     */
    @GetMapping("baseSaleAttrList")
    public Result<List<SaleAttrInfoDTO>> getBaseSaleAttrList() {
        List<SaleAttrInfoDTO> saleAttrInfoList = spuService.getbaseSaleAttrList();
        return Result.ok(saleAttrInfoList);
    }

    /**
     * 保存SPU信息
     */
    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfoParam spuInfoParam) {
        spuService.saveSpuInfo(spuInfoParam);
        return Result.ok();
    }

}
